import { NativeModules, Platform } from 'react-native';

const LINKING_ERROR =
  `The package 'HXPhotoPickerModule' doesn't seem to be linked. Make sure: \n\n` +
  Platform.select({ ios: "- You have run 'pod install'\n", android: '' }) +
  '- You rebuilt the app after installing the package\n';

const HXPhotoPickerModule = NativeModules.HXPhotoPickerModule
  ? NativeModules.HXPhotoPickerModule
  : new Proxy(
      {},
      {
        get() {
          throw new Error(LINKING_ERROR);
        },
      }
    );

interface PhotoResult {
  uri: string;
  width: number;
  height: number;
  type: 'image' | 'video';
}

export default {
  openPicker: (options = {}): Promise<PhotoResult[]> => {
    return HXPhotoPickerModule.openPicker(options);
  },
};
